<!-- 校验用户是否登录 -->

@@include('../comm.html')
<script src="/assets/vendors/nprogress/nprogress.js"></script>
<script src="/assets/vendors/jquery/jquery.js"></script>
<script src="/assets/vendors/bootstrap/js/bootstrap.js"></script>
<script src="/assets/vendors/art-template/template-web.js"></script>

<script>
    //全局设置token
    $.ajaxSetup({
        beforeSend: function(xhr) {
            //获取token
            const token = localStorage.getItem('token')
            xhr.setRequestHeader('Authorization', token)
        },
        timeout: 10000
    })

    $.ajax(`${baseUrl}/login/status`, {
        success: function(res) {
            // console.log('res', res);
            if (res.data && res.data.isLogin) {
                console.log('登录成功');
                // 全局保存 userId
                window.userId = res.data.userId
            } else {
                alert('登录失效！')
                location.href = 'login.html'
            }
        },
        error: function(err) {
            console.log('登录校验失败！');
            alert('登录失效！')
            location.href = 'login.html'
        }
    })
</script>